Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function SendMessageA Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, lParam As Any) As Long


Private Sub SetCtlEx(ByVal hwnd As Long, ByRef Caption As String, ByVal xLeft As Long, ByVal xTop As Long, xMaxWidth, xHeight)
  Dim xType1 As RECT
  Dim hFont As Long
  Dim hFontOld As Long
  Dim hdc As Long
  Dim xLong1 As Long
  
  hdc = CreateCompatibleDC(0&)
  If Not hdc = 0& Then
    hFont = SendMessageA(hwnd, &H31&, 0&, ByVal 0&)
    If Not hFont = 0& Then Call SelectObject(hdc, hFont)
    xLong1 = Len(Caption)
    xType1.Right = &H3FFF&
    xType1.Bottom = &H3FFF&
    If Not DrawText(xLong1, Caption, xType1, &H410&) = 0& Then
      'if not AdjustWindowRect(
      End If
    If Not hFontOld = 0& Then Call SelectObject(hdc, hFontOld)
    Call DeleteDC(hdc)
    End If
  End Sub
